package com.klhappy.houyuan.view;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

import com.klhappy.houyuan.HouYuanApplication;
import com.klhappy.houyuan.R;
import com.klhappy.houyuan.utils.ConfigManager;

public class AbsActivity extends Activity {
	private Toast toast;
	private Dialog mProgressDialog = null;
	
	public ConfigManager mConfigManage = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mConfigManage = getAppEnv().getConfigManager();
	}

	public HouYuanApplication getAppEnv() {
		return (HouYuanApplication)getApplication();
	}
	
	public void showDialog(String msg) {
		mProgressDialog = new Dialog(AbsActivity.this, R.style.progress_dialog);
		mProgressDialog.setContentView(R.layout.dialog);
		mProgressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
		TextView tv_Msg = (TextView) mProgressDialog.findViewById(R.id.id_tv_loadingmsg);
		tv_Msg.setText(msg);
		mProgressDialog.show();
	}
	
	public void closeDialog() {
		if(mProgressDialog != null) {
			mProgressDialog.dismiss();
			mProgressDialog = null;
		}
	}
	
	public void showToast( String msg) {
		if (toast != null){
			toast.cancel();
		}
		toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
		toast.show();
	}

	public void showToast( int msg) {
		if (toast != null){
			toast.cancel();
		}
		toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
		toast.show();
	}

	public void showToastx(String msg){
		if (toast != null){
			toast.cancel();
		}
		toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
		//可以控制toast显示的位置
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.show();

	}

}
